package edu.hawaii.teams.halealohacli.command;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import org.wattdepot.client.WattDepotClient;
import org.junit.Test;

/**
 * Test cases to test functionality of SetBaseLine class.
 * 
 * @author Hansen Cheng
 *
 */
public class TestSetBaseLine {
  
  /**
   * Performs testing to ensure SetBaseLine class is running properly.
   * 
   * @throws Exception - error.
   */
  @Test
  public void testBaseLine() throws Exception {
    
    // For connecting to the server and the SetBaseLine class
    WattDepotClient client = new WattDepotClient("http://server.wattdepot.org:8190/wattdepot/");
    String[] baseCommand = null;
    
    //First case to test inequality
    SetBaseLine sbOne = new SetBaseLine();
    String splits = "\\s";
    String command = "Lehua 2011-12-10"; 
   
    baseCommand = command.split(splits);
    
    String output = sbOne.getData(client, baseCommand);
    String values = "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24";
    assertNotSame("Test inequality", output, values);
    
    //Reset the array of commands to null for next test case
    baseCommand = null;
    
    //Second case to test equality and size of output
    SetBaseLine sbTwo = new SetBaseLine();
    SetBaseLine sbThree = new SetBaseLine();
    String inputs = "Ilima 2011-12-09";
    baseCommand = inputs.split(splits);
    String[] splitValue = null;
    double[] hourValue = new double[24];
    String output1 = sbTwo.getData(client, baseCommand);
    String output2 = sbThree.getData(client, baseCommand);
    assertEquals("Test if outputs are equal", output1, output2);
    assertTrue("Test length of output", output1.length() > 0);
    
    baseCommand = null;
    
    //Test size of array
    splitValue = output1.split(splits); 
    for (int i = 1; i < splitValue.length; i++) {
      hourValue[i - 1] = Double.parseDouble(splitValue[i]);
    }
    assertSame("Test size of array", hourValue.length, 24);
  }

}
